#ifndef __TEXTUREIMPORTER_H__
#define __TEXTUREIMPORTER_H__

#include "../FileServer/FileServer.h"
#include <IL/il.h>
#include <IL/ilu.h>
#include <IL/ilut.h>
#include <gl/gl.h>
#include <map>
#include <iostream>

struct TextureStruct
{
	std::string name;
	GLuint		texture;
	ILubyte*	iL_Data;
	ILint		iL_IMAGE_BPP;
	ILint		iL_IMAGE_WIDTH;
	ILint		iL_IMAGE_HEIGHT;
	ILint		iL_IMAGE_FORMAT;
};

class TextureImporter
{
public:
	static TextureImporter* GetInstance()
	{
		if( m_pInstance == NULL )
		{
			m_pInstance = new TextureImporter();
		}

		return m_pInstance;
	}

	~TextureImporter();

	void LoadTexture( const std::string& name );

	bool GetTextureData( const std::string& name, TextureStruct& ts );

private:
	TextureImporter();

	class Garbo
	{
	public:
		~Garbo()
		{
			if( !TextureImporter::m_pInstance )
			{
				delete TextureImporter::m_pInstance;
				TextureImporter::m_pInstance = NULL;
			}
		}

		static Garbo garbo;
	};

	static TextureImporter*	m_pInstance;

	std::map<std::string, ILuint>		m_ILTextures;
	std::map<std::string, GLuint>		m_Textures;
	std::map<std::string, ILubyte*>		m_IL_Data;
	std::map<std::string, ILint>		m_IL_IMAGE_BPP;
	std::map<std::string, ILint>		m_IL_IMAGE_WIDTH;
	std::map<std::string, ILint>		m_IL_IMAGE_HEIGHT;
	std::map<std::string, ILint>		m_IL_IMAGE_FORMAT;

	bool ExistTexture( const std::string& name );
};

#endif //__TEXTUREIMPORTER_H__